GET_FILENAME_COMPONENT(DIRNAME ${CMAKE_CURRENT_LIST_DIR} NAME)
SET(PLUGIN_NAME plugin.${DIRNAME})
SET_PROPERTY(GLOBAL APPEND PROPERTY CONVERTER_PLUGIN ${PLUGIN_NAME})

INCLUDE_DIRECTORIES(include)

SET(PLUGIN_SRC
  src/SCTConverterPlugin.cc
  src/SCTUpgradeConverterPlugin.cc
  )
ADD_LIBRARY(${PLUGIN_NAME} SHARED ${PLUGIN_SRC})
INSTALL(TARGETS ${PLUGIN_NAME}
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )


LIST(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
FIND_PACKAGE(ROOT REQUIRED)
INCLUDE(${ROOT_USE_FILE})
INCLUDE_DIRECTORIES(include)

SET(ROOTProducer_name ROOTProducer)
SET(ROOTProducer_SOURCES
  src/ROOTProducer.cpp
  src/DemoHardware.cpp
  )

ROOT_GENERATE_DICTIONARY(${ROOTProducer_name}_ROOT  include/ROOTProducer.h include/DemoHardware.h)
ADD_LIBRARY(${ROOTProducer_name} SHARED ${ROOTProducer_SOURCES} ${ROOTProducer_name}_ROOT.cxx)
TARGET_LINK_LIBRARIES(${ROOTProducer_name} EUDAQ ${EUDAQ_THREADS_LIB} ${ROOT_LIBRARIES} ${ADDITIONAL_LIBRARIES})

INSTALL(TARGETS ${ROOTProducer_name}
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )

IF(${ROOT_VERSION_MAJOR} GREATER 5)
  SET(ROOTProducer_PCM ${CMAKE_CURRENT_BINARY_DIR}/lib${ROOTProducer_name}_ROOT_rdict.pcm)
  SET(ROOTProducer_MAP ${CMAKE_CURRENT_BINARY_DIR}/lib${ROOTProducer_name}_ROOT.rootmap)
  INSTALL(FILES
    ${ROOTProducer_PCM}
    ${ROOTProducer_MAP}
    DESTINATION lib
    )
ENDIF()
